package compositeExpression;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import visitor.Visitor;
import exceptions.IllegalContextException;

public class Cond extends BooleanExpression {

	 private List<Expression> termb;
	    
	    public Cond(Termb termb) {
	        
	        this.termb = new LinkedList();
	        this.termb.add(termb);
	    }
	    
	    @Override
	    public void add(Expression termb) {
	        
	        this.termb.add(termb);
	    }// add

	    public List<Expression> getState() {
	        
	        return termb;
	    }// getState

	    @Override
	    public void toAssess(String p) throws IllegalContextException {
	        
	        for (Expression tb : termb) {
	            
	            tb.toAssess(p);
	        }
	    }
	    
	    @Override
	    public String toString() {
	        
	        StringBuilder sb = new StringBuilder();
	        Iterator<Expression> it = termb.iterator();
	        
	        sb.append(it.next());
	        while (it.hasNext()) {
	            
	            sb.append(" || ").append(it.next());
	            
	        }
	        return sb.toString();
	    }
	    
	    @Override
	    public void accept(Visitor v) {
	        v.visit(this);
	    }
	    
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((termb == null) ? 0 : termb.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (!(obj instanceof Cond))
				return false;
			Cond other = (Cond) obj;
			if (termb == null) {
				if (other.termb != null)
					return false;
			} else if (!termb.equals(other.termb))
				return false;
			return true;
		}

		

}
